<template>
<div class="bg-login">
  <div class="login-box">
    <h2>登陆界面</h2>

    <form action="">
      <div class="login-field">
        <input type="text" v-model="loginForm.username" placeholder="用户名">
      </div>
      <div class="login-field">
       <input type="password" v-model="loginForm.password" placeholder="密码">
      </div>
      
      <button @click="login">登录</button> 
      <button @click="loginup">注册</button>  

    </form>

  </div>
  </div>
</template>

<script>
// import { mapMutations } from 'vuex'
export default {
    data(){
        return{
            loginForm:{
                username:"",
                password:""
            }
        }
    },
    methods:{
        // ...mapMutations(['$_setStorage']),     
        login(){
            let _this = this;
        if (this.loginForm.username === "" || this.loginForm.password === "") {
            alert("账号或密码不能为空");
        } else {
            this.$axios({
            method: "post",
            url: "/login/signin",
            data: _this.loginForm
            }).then(res => {
                console.log(res.data);
                // _this.$_setStorage({ Authorization: res.data.token });
                this.$router.push("/first");
                alert("登录成功")
            }).catch(error => {
                
                // console.log(error);
                alert("账号或密码错误");
            });

                    
                }
            },
            loginup(){
              this.$router.push("/signup")
            }
        }
}
</script>

<style scoped="scoped">

body{
  width: 100%;
  margin: 0;
  padding: 0;
}
.bg-login{
  height: 100%;
  width: 100%;
	background:url('../assets/login.jpg')  no-repeat center center;
  background-size: cover;
  /* 把背景扩展足够大 覆盖背景区域 */
}
.login-box{
	position: absolute;
	top: 50%;
	left: 50%;
	transform: translate(-50%,-50%);
	width: 400px;
	padding:40px;
	background: rgba(0,0,0,.8);
	box-sizing: border-box;
	box-shadow: 0 15px  25px rgba(0,0,0,.5);
	border-radius: 10px;
}
.login-box h2{
	margin: 0 0 30px;
	padding: 0;
	text-align: center;
	color: #fff;
}
.login-box .login-field{
	position: relative;
}
.login-box .login-field  input{
	width: 100%;
	padding: 10px 0;
	font-size: 16px;
	color: #fff;
	margin-bottom: 30px;
	border: none;  
	border-bottom: 1px solid #fff;
	background: transparent;
}

.login-box button{
	background: transparent;
	border: none;
	color: #fff;
	background: #03a9f4;
	padding: 10px 20px;
	cursor: pointer;
	border-radius: 5px;
}


</style>